package com.youxue.teachin.set.main.binder;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.library.xtype.DefaultNuwaItemBinder;
import com.youxue.teachin.R;
import com.youxue.teachin.set.main.vo.SheJiaoVO;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-10-06 10:50
 * @version: 9.1.0
 */
public class SheJiaoBinder extends DefaultNuwaItemBinder<SheJiaoVO> {
    private View mRootView;
    private TextView mKey;
    private ImageView mButtonBg;
    private ImageView mButtonFocus;
    private FrameLayout mButtonParent;

    @Override
    public View onCreateView(View convertView, ViewGroup parent, LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.set_main_shejiao_binder, parent, false);
        initView(view);
        return view;
    }

    @Override
    public void onBindView(int positionOfFeeds, View convertView, ViewGroup parent, SheJiaoVO vo) {
        mKey.setText(vo.mTitle);

        mButtonBg.setSelected(vo.isConfirmed);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)mButtonFocus.getLayoutParams();
        if (vo.isConfirmed) {
            params.gravity = Gravity.RIGHT;
        } else {
            params.gravity = Gravity.LEFT;
        }
        mButtonFocus.setLayoutParams(params);
    }

    private void initView(View rootView) {
        mRootView = rootView;
        mKey = (TextView)rootView.findViewById(R.id.key);
        mButtonBg = (ImageView)rootView.findViewById(R.id.button_bg);
        mButtonFocus = (ImageView)rootView.findViewById(R.id.button_focus);
        mButtonParent = (FrameLayout)rootView.findViewById(R.id.button_parent);
    }
}
